package o;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.opengl.GLES10;
import android.text.TextUtils;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.GlideException;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;

public class bsx {
    private static int ˏ = 0;
    private static int ॱ = 50;

    static class a {
        private boolean ʼ;
        private String ʽ;
        private int ˊ;
        private int ˋ;
        private c ˎ;
        private si[] ˏ;
        private zp ॱ;
        private zn ᐝ;

        private a() {
            this.ˋ = -1;
            this.ˊ = -1;
            this.ˎ = c.PIC_TYPE_NORMAL;
            this.ᐝ = new era();
        }
    }

    static class b implements zn {
        private final ImageView ˎ;
        private final String ॱ;

        public b(ImageView imageView, String str) {
            this.ˎ = imageView;
            this.ॱ = str;
        }

        public boolean ॱ(@Nullable GlideException glideException, Object obj, zz zzVar, boolean z) {
            if (this.ॱ != null) {
                erm.ˏ().ˋ(this.ˎ, this.ॱ);
            } else {
                if (glideException != null) {
                    Logger.ˏ("ImageUtils", "ImageRequest onException: " + glideException.toString() + " , model : " + obj);
                } else {
                    Logger.ˏ("ImageUtils", "ImageRequest onException! model : " + obj);
                }
                eso.ॱ(glideException, obj);
            }
            return true;
        }

        public boolean ˎ(Object obj, Object obj2, zz zzVar, rz rzVar, boolean z) {
            return false;
        }
    }

    enum c {
        PIC_TYPE_GIF,
        PIC_TYPE_NORMAL
    }

    static class d extends aac<Bitmap> {
        private ImageView ˊ;
        private String ॱ;

        public /* synthetic */ void onResourceReady(@NonNull Object obj, @Nullable aaf o_aaf) {
            ˋ((Bitmap) obj, o_aaf);
        }

        public d(ImageView imageView, String str) {
            this.ˊ = imageView;
            this.ॱ = str;
        }

        public void ˋ(@NonNull Bitmap bitmap, @Nullable aaf<? super Bitmap> o_aaf__super_android_graphics_Bitmap) {
            if (this.ˊ != null) {
                Object tag = this.ˊ.getTag();
                if ((tag instanceof String) && this.ॱ != null && this.ॱ.equals(tag)) {
                    this.ˊ.setImageBitmap(bitmap);
                }
            }
        }
    }

    public static void ˋ(Context context, ImageView imageView, String str) {
        imageView.setImageResource(o.bqz.c.ʼ);
        imageView.setTag(str);
        if (!cgy.ˎ(str)) {
            try {
                ˏ(Glide.ˏ(context).ॱ().ˎ(str)).ˏ(new d(imageView, str));
            } catch (IllegalArgumentException e) {
                bqx.ॱ("ForumImageUtils", "circleImage Glide IllegalArgumentException");
            }
        }
    }

    public static void ˏ(Context context, ImageView imageView, String str) {
        try {
            ˏ(Glide.ˏ(context).ˏ(str)).ˏ(imageView);
        } catch (IllegalArgumentException e) {
            bqx.ॱ("ForumImageUtils", "circleImage Glide IllegalArgumentException");
        }
    }

    private static ro ˏ(ro roVar) {
        return roVar.ॱ((zp) zp.ˊ().ˎ(o.bqz.c.ʼ));
    }

    public static void ˊ(ImageView imageView, String str) {
        if (imageView == null || str == null) {
            Logger.ˎ("ForumImageUtils", "asynLoadImgByDrawable param is null");
            return;
        }
        ro ˏ = ˏ(imageView.getContext(), str);
        if (ˏ == null) {
            Logger.ˏ("ForumImageUtils", "asynLoadImgByDrawable DrawableRequestBuilder is null");
        } else {
            ˏ.ॱ(new era()).ˏ(imageView);
        }
    }

    protected static ro ˏ(Context context, String str) {
        return ˏ(context, str, false);
    }

    protected static ro ˏ(Context context, String str, boolean z) {
        try {
            zp zpVar = (zp) ((zp) new zp().ॱ(true)).ˊ(tf.ˏ);
            if (z) {
                zpVar = (zp) zpVar.ॱॱ();
            }
            return ˎ(context, str, zpVar);
        } catch (IllegalArgumentException e) {
            Logger.ˏ("ForumImageUtils", "getImageBuilder Glide IllegalArgumentException");
            return null;
        }
    }

    protected static ro ˎ(Context context, String str, zp zpVar) {
        ro roVar = null;
        try {
            roVar = Glide.ˏ(context).ˏ(str).ॱ((ze) zpVar);
        } catch (IllegalArgumentException e) {
            Logger.ˏ("ForumImageUtils", "getImageBuilder Glide IllegalArgumentException");
        }
        return roVar;
    }

    public static void ॱ(ImageView imageView, String str) {
        ˊ(imageView, str, (String) null, new si[0]);
    }

    protected static void ˊ(ImageView imageView, String str, String str2, si... siVarArr) {
        Context context = null;
        a aVar = new a();
        aVar.ʽ = str;
        aVar.ˏ = siVarArr;
        if (imageView != null) {
            context = imageView.getContext();
        }
        aVar.ॱ = ˊ(context);
        if (!TextUtils.isEmpty(str2)) {
            aVar.ᐝ = new b(imageView, str2);
        }
        ˏ(imageView, aVar);
    }

    public static void ˎ(ImageView imageView, String str) {
        Context context;
        a aVar = new a();
        aVar.ˎ = c.PIC_TYPE_GIF;
        aVar.ʽ = str;
        if (imageView != null) {
            context = imageView.getContext();
        } else {
            context = null;
        }
        aVar.ॱ = ˊ(context);
        aVar.ᐝ = null;
        ˏ(imageView, aVar);
    }

    private static void ˏ(ImageView imageView, a aVar) {
        if (imageView != null) {
            ro ˋ = ˋ(imageView.getContext(), aVar);
            if (ˋ != null) {
                ˋ.ˏ(imageView);
            }
        }
    }

    private static ro ˋ(Context context, a aVar) {
        if (aVar == null || aVar.ʽ == null) {
            return null;
        }
        ro ˊ;
        if (aVar.ˎ == c.PIC_TYPE_GIF) {
            ˊ = ˊ(context, aVar.ʽ, aVar.ʼ);
        } else {
            ˊ = ॱ(context, aVar.ʽ, aVar.ʼ);
        }
        if (ˊ == null) {
            Logger.ˏ("ImageUtils", "asynLoadImage builder is null.");
            return null;
        }
        if (aVar.ॱ != null) {
            ˊ.ॱ(aVar.ॱ);
        }
        if (aVar.ˋ > 0 && aVar.ˊ > 0) {
            ze zpVar = new zp();
            zpVar.ˊ(aVar.ˋ, aVar.ˊ);
            ˊ.ॱ(zpVar);
        }
        if (aVar.ˏ != null) {
            for (si siVar : aVar.ˏ) {
                if (siVar != null) {
                    ˊ = ˊ.ॱ(zp.ˎ(siVar));
                }
            }
        }
        if (aVar.ᐝ != null) {
            return ˊ.ॱ(aVar.ᐝ);
        }
        return ˊ;
    }

    protected static ro<xt> ˊ(Context context, String str, boolean z) {
        ro<xt> roVar;
        try {
            roVar = (ro) Glide.ˏ(context).ʼ().ˎ(str).ˊ(tf.ˏ);
            if (z) {
                try {
                    roVar = roVar.ॱ((zp) new zp().ॱॱ());
                } catch (IllegalArgumentException e) {
                    Logger.ˏ("SecureRequestBuilders", "getBitmapBuilder Glide IllegalArgumentException");
                    return roVar;
                }
            }
        } catch (IllegalArgumentException e2) {
            roVar = null;
            Logger.ˏ("SecureRequestBuilders", "getBitmapBuilder Glide IllegalArgumentException");
            return roVar;
        }
        return roVar;
    }

    protected static ro<Bitmap> ॱ(Context context, String str, boolean z) {
        ro<Bitmap> roVar;
        try {
            roVar = (ro) Glide.ˏ(context).ॱ().ˎ(str).ˊ(tf.ˏ);
            if (z) {
                try {
                    roVar = roVar.ॱ((zp) new zp().ॱॱ());
                } catch (IllegalArgumentException e) {
                    Logger.ˏ("SecureRequestBuilders", "getBitmapBuilder Glide IllegalArgumentException");
                    return roVar;
                }
            }
        } catch (IllegalArgumentException e2) {
            roVar = null;
            Logger.ˏ("SecureRequestBuilders", "getBitmapBuilder Glide IllegalArgumentException");
            return roVar;
        }
        return roVar;
    }

    private static zp ˊ(Context context) {
        zp zpVar = new zp();
        if (context == null) {
            return zpVar;
        }
        return (zp) zpVar.ˎ(o.dky.a.ˑ);
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static android.graphics.Bitmap ˊ(android.graphics.Bitmap r6, java.lang.String r7) {
        /*
        if (r7 != 0) goto L_0x0003;
    L_0x0002:
        return r6;
    L_0x0003:
        r1 = 0;
        r2 = new java.io.ByteArrayOutputStream;
        r2.<init>();
        r0 = ॱ(r7);
        r3 = ॱ;	 Catch:{ Exception -> 0x0043 }
        r6.compress(r0, r3, r2);	 Catch:{ Exception -> 0x0043 }
        r0 = r2.toByteArray();	 Catch:{ Exception -> 0x0043 }
        r0 = r0.clone();	 Catch:{ Exception -> 0x0043 }
        r0 = (byte[]) r0;	 Catch:{ Exception -> 0x0043 }
        r3 = 0;
        r4 = r0.length;	 Catch:{ Exception -> 0x0043 }
        r0 = android.graphics.BitmapFactory.decodeByteArray(r0, r3, r4);	 Catch:{ Exception -> 0x0043 }
        r2.close();	 Catch:{ IOException -> 0x0029 }
    L_0x0025:
        if (r0 == 0) goto L_0x0002;
    L_0x0027:
        r6 = r0;
        goto L_0x0002;
    L_0x0029:
        r1 = move-exception;
        r2 = "ForumImageUtils";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "close e:";
        r3 = r3.append(r4);
        r1 = r3.append(r1);
        r1 = r1.toString();
        o.bqx.ˋ(r2, r1);
        goto L_0x0025;
    L_0x0043:
        r0 = move-exception;
        r3 = "ForumImageUtils";
        r4 = new java.lang.StringBuilder;	 Catch:{ all -> 0x007c }
        r4.<init>();	 Catch:{ all -> 0x007c }
        r5 = "compress e:";
        r4 = r4.append(r5);	 Catch:{ all -> 0x007c }
        r0 = r4.append(r0);	 Catch:{ all -> 0x007c }
        r0 = r0.toString();	 Catch:{ all -> 0x007c }
        o.bqx.ˋ(r3, r0);	 Catch:{ all -> 0x007c }
        r2.close();	 Catch:{ IOException -> 0x0061 }
        r0 = r1;
        goto L_0x0025;
    L_0x0061:
        r0 = move-exception;
        r2 = "ForumImageUtils";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "close e:";
        r3 = r3.append(r4);
        r0 = r3.append(r0);
        r0 = r0.toString();
        o.bqx.ˋ(r2, r0);
        r0 = r1;
        goto L_0x0025;
    L_0x007c:
        r0 = move-exception;
        r2.close();	 Catch:{ IOException -> 0x0081 }
    L_0x0080:
        throw r0;
    L_0x0081:
        r1 = move-exception;
        r2 = "ForumImageUtils";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "close e:";
        r3 = r3.append(r4);
        r1 = r3.append(r1);
        r1 = r1.toString();
        o.bqx.ˋ(r2, r1);
        goto L_0x0080;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.bsx.ˊ(android.graphics.Bitmap, java.lang.String):android.graphics.Bitmap");
    }

    private static CompressFormat ॱ(String str) {
        CompressFormat compressFormat = CompressFormat.JPEG;
        if (str.contains(".jpg")) {
            return CompressFormat.JPEG;
        }
        if (str.contains(".png")) {
            return CompressFormat.PNG;
        }
        if (str.contains(".webp")) {
            return CompressFormat.WEBP;
        }
        return compressFormat;
    }

    public static int ˋ() {
        if (ˏ <= 0) {
            ˏ = ˊ();
        }
        return ˏ;
    }

    public static int ˊ() {
        EGL10 egl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay eglGetDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        egl10.eglInitialize(eglGetDisplay, new int[2]);
        EGLConfig[] eGLConfigArr = new EGLConfig[1];
        egl10.eglChooseConfig(eglGetDisplay, new int[]{12351, 12430, 12329, 0, 12339, 1, 12344}, eGLConfigArr, 1, new int[1]);
        EGLConfig eGLConfig = eGLConfigArr[0];
        EGLSurface eglCreatePbufferSurface = egl10.eglCreatePbufferSurface(eglGetDisplay, eGLConfig, new int[]{12375, 64, 12374, 64, 12344});
        EGLContext eglCreateContext = egl10.eglCreateContext(eglGetDisplay, eGLConfig, EGL10.EGL_NO_CONTEXT, new int[]{12440, 1, 12344});
        egl10.eglMakeCurrent(eglGetDisplay, eglCreatePbufferSurface, eglCreatePbufferSurface, eglCreateContext);
        int[] iArr = new int[1];
        GLES10.glGetIntegerv(3379, iArr, 0);
        egl10.eglMakeCurrent(eglGetDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        egl10.eglDestroySurface(eglGetDisplay, eglCreatePbufferSurface);
        egl10.eglDestroyContext(eglGetDisplay, eglCreateContext);
        egl10.eglTerminate(eglGetDisplay);
        return iArr[0];
    }

    public static boolean ˎ(String str) {
        return !TextUtils.isEmpty(str) && (str.endsWith(".gif") || str.endsWith(".GIF"));
    }
}
